/*
 * File: calculator.h
 * Author:  Yin Lijun <yinlijun2004@gmail.com>
 * Brief:   calculator header.
 *
 * Copyright (c) 2011 - 2012  Yin Lijun <yinlijun2004@gmail.com>
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * History:
 * ================================================================
 * 2012-03-12 Yin Lijun <yinlijun2004@gmail.com> created
 *
 */
#ifndef CALCULATOR_H
#define CALCULATOR_H

#include "typedef.h"

#ifdef __cplusplus
extern "C" {
#endif

struct _Calculator;
typedef struct _Calculator Calculator;
struct _CalculatorInterface;
typedef struct _CalculatorInterface CalcIface;

typedef void* (*CalculationFunc)(void* last_op, void** data, int size);
typedef int (*NeedBacktraceFunc)(void* data);
typedef int (*OprdsNumByOperFunc)(void* oper);

struct _CalculatorInterface
{
	DestoryFunc data_dest_func;
	DestoryFunc op_dest_func;
	CompareFunc op_prior_cmp_func;
	NeedBacktraceFunc need_bt_func;
	CalculationFunc calc_func;
	OprdsNumByOperFunc get_oprs_num_func;
};

Calculator* calc_create(CalcIface* ci);
Ret calc_on_data(Calculator* thiz, void* data);
Ret calc_on_operator(Calculator* thiz, void* oper);
Ret calc_on_end(Calculator* thiz);
Ret calc_foreach_data(Calculator* thiz, VisitFunc visit, void* ctx);
Ret calc_foreach_op(Calculator* thiz, VisitFunc visit, void* ctx);
void* calc_get_result(Calculator* thiz);
Ret calc_destroy(Calculator* thiz);

#ifdef __cplusplus
}
#endif

#endif
